﻿namespace StringsAndTextProcessing
{
    using System;
    using System.Text;

    class CatchTextBetwenTags
    {
        // 1.2.13.05. You are given a text. Write a program that changes the text in all regions surrounded by
        // the tags <upcase> and </upcase> to uppercase. The tags cannot be nested. Example:
        // We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.
        // The expected result:
        // We are living in a YELLOW SUBMARINE. We don't have ANYTHING else.

        static void Main()
        {
            var text = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
            var sb = new StringBuilder();

            for (var i = 0; i < text.Length; i++)
            {
                if ((text[i] == '<'))
                {
                    i += 8;

                    while (text[i] != '<')
                    {
                        sb.Append(text[i].ToString().ToUpper());
                        i++;
                    }

                    i += 8; // </upcase>.Length = 8
                }
                else
                {
                    sb.Append(text[i]);
                }
            }

            Console.WriteLine(sb.ToString());
        }
    }
}